package com.example.charlotte.snakegame;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Build;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.view.View;


public class BaseActivity extends Activity {
    private SharedPreferences saved;
    private boolean bgMusic;
    private GameMusic music;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                    | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
            //View.SYSTEM_UI_FLAG_HIDE_NAVIGATION :隐藏虚拟导航按键
            //View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY：黏性全屏沉浸模式
            //顶部下滑会显示出透明的状态栏和虚拟导航栏，在一段时间以后自动恢复成全屏沉浸模式
        }
        setContentView(R.layout.activity_base);
        saved = PreferenceManager.getDefaultSharedPreferences(this);
        bgMusic = saved.getBoolean("bgmusic", true);
        music=new GameMusic(this);

    }

    public void playBGM(){
        if (bgMusic) {
            Intent intent = new Intent(BaseActivity.this, BGMService.class);
            startService(intent);
        }

    }
    public void stopBGM() {
        if (bgMusic) {
            Intent intent = new Intent(BaseActivity.this, BGMService.class);
            stopService(intent);
        }
    }
    public void re(View view) {
        music.startMusic(3);
        this.finish();
    }


}